#!/bin/bash
#Date 2022/1/10
#mail it-arch
echo "##########################################"
echo "Auto Install zabbix-proxy.              ##"
echo "Press Ctrl + C to cancel                ##"
echo "Any key to continue                     ##"
echo "##########################################"
echo "1 Install zabbix3.0-proxy"
echo "2 Install zabbix3.2-proxy"
echo "3 EXIT"
read -p "Input your choce:" I
if [ "$I" == "1" ];then
	URL=http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
elif [ "$I" == "2" ];then
	URL=http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
elif [ "$I" == "3" ];then
	echo "you choce channel!"
	exit 1;
else
	echo "input Error! Place input{1|2|3}"
	exit 0;
fi
PIP=`ifconfig |grep "inet addr" |grep -v "127.0.0.1" |awk -F: '{ print $2 }'| awk '{ print $1}'|head -1`
read -p "Place input zabbix server ipaddress:" SIP
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ]
then
iptables -I INPUT -p tcp --dport 10051 -j ACCEPT &&
iptables -I INPUT -p tcp --dport 10050 -j ACCEPT &&
/etc/init.d/iptables save >/dev/null 2>&1
else
	echo -e "\033[32m iptables is stopd\033[0m"
fi
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
ntpdate -s time1.aliyun.com 
echo "*/5 * * * * /usr/sbin/ntpdate -s time1.aliyun.com">>/var/spool/cron/root
###################################################
rpm -ivh  $URL
yum install zabbix-agent -y
sed -i "s/Server=127.0.0.1/Server=$SIP/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix\ server/Hostname=$PIP/g" /etc/zabbix/zabbix_agentd.conf
echo "Timeout=30">>/etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix-agent start
chkconfig zabbix-agent on 
STATE=`ps -ef |grep zabbix_agentd|grep -v grep|wc -l`
PORT=`netstat -lntup|grep zabbix_agent|wc -l`
if [ $STATE > 0 -a $PORT > 0 ];then
	echo -e "\033[32m zabbix-agent is install success! \033[0m"
	echo -e "\033[32m zabbix-agent HOSTNAME:$PIP \033[0m"
	echo -e "\033[32m zabbix-server IP:$SIP \033[0m"
else
	echo "\033[32m zabbix-agent error! place see /var/log/zabbix/zabbix_agentd.log \033[0m"
fi
